<template>
  <div>
    <img :src="$pre+info.img" alt />
    <div>{{info.goodsname}}</div>
    <div>价格:{{info.price}}</div>
    <div v-html="info.description"></div>
    <!-- <v-button @click="$router.push('/index/shop')">前往购物车</v-button>
    <v-button @click="addshop">加入购物车</v-button> -->
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" />
      <van-goods-action-icon icon="cart-o" text="购物车" @click="$router.push('/index/shop')"/>
      <van-goods-action-icon icon="shop-o" text="店铺" />
      <van-goods-action-button text="加入购物车" type="warning" @click="addshop"/>
      <van-goods-action-button text="立即购买" type="danger"/>
    </van-goods-action>
  </div>
</template>

<script>
import { reqdetail } from "../../http/http";
import { reqcartadd } from "../../http/http";
export default {
  data() {
    return {
      info: {}
    };
  },
  mounted() {
    reqdetail({
      id: this.$route.params.id
    }).then(res => {
      this.info = res.data.list[0];
      this.info.specsattr = this.info.specsattr.split(",");
    });
  },
  methods: {
    addshop() {
      reqcartadd({
        uid: JSON.parse(localStorage.getItem("isLogin")).uid,
        goodsid: this.$route.params.id,
        num: 1
      }).then(res => {
        if (res.data.code == 200) {
          alert(res.data.msg);
        } else {
          alert(res.data.msg);
        }
      });
    }
  }
};
</script>

<style scoped>
img {
  width: 100vw;
}
</style>